package com.washmadam.service.service.communicate.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.washmadam.service.common.enums.DeleteEnum;
import com.washmadam.service.common.enums.StatusEnum;
import com.washmadam.service.db.dao.CustomerOrderCommunicateMapper;
import com.washmadam.service.db.dto.CustomerOrderCommunicate;
import com.washmadam.service.db.example.CustomerOrderCommunicateExample;
import com.washmadam.service.service.communicate.CustomerOrderCommunicateQueryService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class CustomerOrderCommunicateQueryServiceImpl implements CustomerOrderCommunicateQueryService {
	@Autowired
	CustomerOrderCommunicateMapper customerOrderCommunicateMapper;
	@Override
	public List<CustomerOrderCommunicate> getAllCustomerOrderCommunicateByOrderId(Long orderId) {
		CustomerOrderCommunicateExample example = new CustomerOrderCommunicateExample();
		example.createCriteria()
		       .andCustomerOrderIdEqualTo(orderId)
		       .andStatusEqualTo(StatusEnum.ENABLE.getCode())
		       .andIsDeleteEqualTo(DeleteEnum.NORMAL.getCode());
		example.setOrderByClause("id desc");
		return customerOrderCommunicateMapper.selectByExample(example);
	}
	@Override
	public CustomerOrderCommunicate getLastCommunicateMessage(Long orderId) {
		List<CustomerOrderCommunicate> list = getAllCustomerOrderCommunicateByOrderId(orderId);
		if(CollectionUtils.isNotEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

}
